import json
import pyecharts

# 基础入门——全局配置项
from pyecharts.charts import Map  # 地图
from pyecharts.options import TitleOpts, LegendOpts, ToolboxOpts, VisualMapOpts, LabelOpts

# 创建一个地图对象
map = Map()

# 数据准备
data = [("北京市", 78), ("上海市", 56), ("青海省", 89), ("福建省", 22)]

# 添加数据
map.add("地图实例", data, "china")

# 设置全局配置项
map.set_global_opts(
    title_opts=TitleOpts(title="地图", pos_left="center", pos_bottom='1%'),  # 标题设置
    legend_opts=LegendOpts(is_show=True),  # 图例是否展示
    toolbox_opts=ToolboxOpts(is_show=True),  # 工具箱是否展示
    visualmap_opts=VisualMapOpts(is_show=True,
                                 is_piecewise=True,
                                 pieces=[
                                     {"min": 1, "max": 30, "label": "1~30", "color": "#668B8B"},
                                     {"min": 31, "max": 60, "label": "31~60", "color": "#2E8B57"},
                                     {"min": 61, "max": 90, "label": "61~90", "color": "#4682B4"},
                                 ])  # 视觉映射是否展示
)
map.render()
